<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxShopCart;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxShopCartController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxShopCart(['user']), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user.user_avatar','头像')->image('',30,30);
            $grid->column('user.user_name','用户');
            $grid->column('goods_pic')->image('',50);
            $grid->column('goods_name');
            $grid->column('goods_product');
            $grid->column('vip_price');
            $grid->column('price');
            $grid->column('num');
//            $grid->column('user_id');
//            $grid->column('goods_id');
//            $grid->column('product_id');
            $grid->column('is_check')->using([0=>'否',1=>'是'])->label([
                0=>'red',
                1=>'green'
            ]);
            $grid->column('state')->using([0 => '正常', 1 => '用户删除', 2 => '已下单', 3 => '商品下架'])->label([
                0 => 'blue',
                1 => 'primary',
                2 => 'green',
                3 => 'orange2'
            ]);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableBatchDelete();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxShopCart(), function (Show $show) {
            $show->field('id');
            $show->field('goods_pic');
            $show->field('goods_name');
            $show->field('goods_product');
            $show->field('vip_price');
            $show->field('price');
            $show->field('num');
            $show->field('user_id');
            $show->field('goods_id');
            $show->field('product_id');
            $show->field('is_check');
            $show->field('state');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxShopCart(), function (Form $form) {
            $form->display('id');
            $form->text('goods_pic');
            $form->text('goods_name');
            $form->text('goods_product');
            $form->text('vip_price');
            $form->text('price');
            $form->text('num');
            $form->text('user_id');
            $form->text('goods_id');
            $form->text('product_id');
            $form->text('is_check');
            $form->text('state');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
